﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using XamlingCore.Infrastructure.View;

namespace XamlingCore.WP.Controls.Buttons
{
    public class XNavigateHyperlinkButton : HyperlinkButton
    {
        protected override void OnClick()
        {
            var dc = DataContext as XContentViewModelBase;
            
            if (dc != null)
            {
                var obj =dc.CreateAndNavigate(ModelName, NavigateParameter);
                dc.NavigateTo(obj);
            }
            else
            {
                throw new InvalidOperationException("Cannot navigate when datacontext is not dervied from XContentViewModelBase");
            }
        }

        public object NavigateParameter
        {
            get { return (object)GetValue(NavigateParameterProperty); }
            set { SetValue(NavigateParameterProperty, value); }
        }

        // Using a DependencyProperty as the backing store for NavigateParameter.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty NavigateParameterProperty =
            DependencyProperty.Register("NavigateParameter", typeof(object), typeof(XNavigateHyperlinkButton), new PropertyMetadata(null));

        

        public string ModelName
        {
            get { return (string)GetValue(ModelNameProperty); }
            set { SetValue(ModelNameProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ModelName.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ModelNameProperty =
            DependencyProperty.Register("ModelName", typeof(string), typeof(XNavigateHyperlinkButton), new PropertyMetadata(null));

        
    }
}
